package com.gxgeek.threadpoolexecutor.executors;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.concurrent.*;

/**
 * @author gaoxing
 * @create 2017-12-20 下午8:38
 */
public class ExecutorsDemo {
    public static void main(String[] args) {
//
//        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
//                                            .setNameFormat("XX-task-%d")
//                                            .build();
//
//        ThreadPoolExecutor executorService = new ThreadPoolExecutor(10, 15, 3, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), Executors.defaultThreadFactory());
//        Executors.newCachedThreadPool();
//        Executors.newSingleThreadExecutor();
//        Executors.newFixedThreadPool(1);
        System.out.println(Runtime.getRuntime().availableProcessors());
        System.out.println(Runtime.getRuntime().freeMemory()/1024/1024/1024);
        System.out.println(Runtime.getRuntime().maxMemory()/1024/1024/1024);
        System.out.println(Runtime.getRuntime().totalMemory()/1024/1024/1024);
//        System.out.println(Runtime.getRuntime().);
//
//        for (int i = 0;i<=100;i++){
//            executorService.execute(()->{
//                System.out.println(Thread.currentThread().getName());
//
//            });
//
//        }
//        System.out.println(s);
//        final CompletableFuture<BigDecimal> future =
//                CompletableFuture.supplyAsync(this::calculate, executorService);


    }

    @Test
    public void thenApply() {
        String result = CompletableFuture.supplyAsync(() -> "hello").thenApply(s -> s + " world").join();
        System.out.println(result);
    }
}
